package com.global.gbinventory.data.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

public class PelangganFrame extends JInternalFrame {

	private static final long serialVersionUID = -8699224959684953705L;
	
	private JPanel panelButtons;
	private JPanel panelInfo;
	
	private JTextField txtFldKode;
	private JTextField txtFldNama;
	private JTextField txtFldHP;
	private JTextField txtFldEmail;
	private JTextField txtFldKota;
	private JTextField txtFldKodePos;
	private JTextField txtFldProvinsi;
	private JTextField txtFldTelepon;
	
	private JTextArea txtAreaKeterangan;
	private JTextArea txtAreaAlamat;
	
	private JLabel lblKode;
	private JLabel lblNama;
	
	private JButton btnNew;
	private JButton btnEdit;
	private JButton btnDelete;
	private JButton btnSave;
	private JButton btnCancel;
	private JButton btnShowList;
	
	/**
	 * Create the frame.
	 */
	public PelangganFrame() {
		//resizeable, closeable, maximizable, iconifiable
		super("Setup Pelanggan", false, true, false, true);
		setBounds(100, 100, 824, 474);
		getContentPane().setLayout(new BorderLayout(0, 0));

		JPanel panelRight = new JPanel();
		panelRight.setPreferredSize(new Dimension(30, 10));
		getContentPane().add(panelRight, BorderLayout.EAST);

		JPanel panelCenter = new JPanel();
		getContentPane().add(panelCenter, BorderLayout.CENTER);
		panelCenter.setLayout(null);

		panelButtons = new JPanel();
		panelButtons.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelButtons.setBounds(20, 11, 744, 40);
		panelCenter.add(panelButtons);
		panelButtons.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		btnNew = new JButton("New");
		panelButtons.add(btnNew);
		
		btnEdit = new JButton("Edit");
		btnEdit.setEnabled(false);
		panelButtons.add(btnEdit);
		
		btnDelete = new JButton("Delete");
		btnDelete.setEnabled(false);
		panelButtons.add(btnDelete);
		
		btnSave = new JButton("Save");
		btnSave.setEnabled(false);
		panelButtons.add(btnSave);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setEnabled(false);
		panelButtons.add(btnCancel);
		
		panelInfo = new JPanel();
		panelInfo.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelInfo.setBounds(20, 63, 744, 316);
		panelCenter.add(panelInfo);
		panelInfo.setLayout(null);

		btnShowList = new JButton("...");
		btnShowList.setBounds(305, 32, 24, 23);
		panelInfo.add(btnShowList);
		
		JLabel lblInfoUmum = new JLabel("Info Umum");
		lblInfoUmum.setFont(new Font("Arial", Font.PLAIN, 11));
		lblInfoUmum.setOpaque(true);
		lblInfoUmum.setBackground(new Color(102, 153, 204));
		lblInfoUmum.setBounds(10, 11, 316, 14);
		panelInfo.add(lblInfoUmum);

		lblKode = new JLabel("Kode Pelanggan* : ");
		lblKode.setFont(new Font("Arial", Font.PLAIN, 11));
		lblKode.setBounds(10, 36, 111, 14);
		panelInfo.add(lblKode);

		txtFldKode = new JTextField();
		txtFldKode.setEditable(false);
		txtFldKode.setBounds(122, 33, 173, 20);
		panelInfo.add(txtFldKode);
		txtFldKode.setColumns(20);

		lblNama = new JLabel("Nama Pelanggan* : ");
		lblNama.setFont(new Font("Arial", Font.PLAIN, 11));
		lblNama.setBounds(10, 67, 111, 14);
		panelInfo.add(lblNama);

		txtFldNama = new JTextField();
		txtFldNama.setEditable(false);
		txtFldNama.setBounds(122, 64, 204, 20);
		panelInfo.add(txtFldNama);
		txtFldNama.setColumns(40);

		JLabel lblInfoKontak = new JLabel("Info Kontak");
		lblInfoKontak.setFont(new Font("Arial", Font.PLAIN, 11));
		lblInfoKontak.setOpaque(true);
		lblInfoKontak.setBackground(new Color(102, 153, 204));
		lblInfoKontak.setBounds(10, 98, 316, 14);
		panelInfo.add(lblInfoKontak);

		JLabel lblNoHp = new JLabel("No. HP :");
		lblNoHp.setFont(new Font("Arial", Font.PLAIN, 11));
		lblNoHp.setBounds(10, 123, 95, 14);
		panelInfo.add(lblNoHp);

		JLabel lblEmail = new JLabel("Email :");
		lblEmail.setFont(new Font("Arial", Font.PLAIN, 11));
		lblEmail.setBounds(10, 157, 95, 14);
		panelInfo.add(lblEmail);

		txtFldHP = new JTextField();
		txtFldHP.setEditable(false);
		txtFldHP.setColumns(20);
		txtFldHP.setBounds(122, 120, 204, 20);
		panelInfo.add(txtFldHP);

		txtFldEmail = new JTextField();
		txtFldEmail.setEditable(false);
		txtFldEmail.setColumns(50);
		txtFldEmail.setBounds(122, 154, 204, 20);
		panelInfo.add(txtFldEmail);

		JLabel lblInfoAlamat = new JLabel("Info Alamat");
		lblInfoAlamat.setFont(new Font("Arial", Font.PLAIN, 11));
		lblInfoAlamat.setBackground(new Color(102, 153, 204));
		lblInfoAlamat.setOpaque(true);
		lblInfoAlamat.setBounds(351, 11, 383, 14);
		panelInfo.add(lblInfoAlamat);

		JLabel lblAlamat = new JLabel("Alamat* : ");
		lblAlamat.setFont(new Font("Arial", Font.PLAIN, 11));
		lblAlamat.setBounds(351, 36, 72, 14);
		panelInfo.add(lblAlamat);

		txtAreaAlamat = new JTextArea();
		txtAreaAlamat.setFont(new Font("Arial", Font.PLAIN, 11));
		txtAreaAlamat.setEditable(false);
		txtAreaAlamat.setBounds(407, 31, 327, 77);
		panelInfo.add(txtAreaAlamat);

		JLabel lblKota = new JLabel("Kota : ");
		lblKota.setFont(new Font("Arial", Font.PLAIN, 11));
		lblKota.setBounds(351, 123, 46, 14);
		panelInfo.add(lblKota);

		txtFldKota = new JTextField();
		txtFldKota.setFont(new Font("Arial", Font.PLAIN, 11));
		txtFldKota.setEditable(false);
		txtFldKota.setBounds(407, 120, 111, 20);
		panelInfo.add(txtFldKota);
		txtFldKota.setColumns(30);
		txtFldKota.setText("Perdagangan");

		JLabel lblKodePos = new JLabel("Kode Pos : ");
		lblKodePos.setFont(new Font("Arial", Font.PLAIN, 11));
		lblKodePos.setBounds(538, 123, 78, 14);
		panelInfo.add(lblKodePos);

		txtFldKodePos = new JTextField();
		txtFldKodePos.setFont(new Font("Arial", Font.PLAIN, 11));
		txtFldKodePos.setEditable(false);
		txtFldKodePos.setBounds(605, 120, 129, 20);
		panelInfo.add(txtFldKodePos);
		txtFldKodePos.setColumns(10);

		JLabel lblProvinsi = new JLabel("Provinsi : ");
		lblProvinsi.setFont(new Font("Arial", Font.PLAIN, 11));
		lblProvinsi.setBounds(351, 157, 60, 14);
		panelInfo.add(lblProvinsi);

		txtFldProvinsi = new JTextField();
		txtFldProvinsi.setFont(new Font("Arial", Font.PLAIN, 11));
		txtFldProvinsi.setEditable(false);
		txtFldProvinsi.setBounds(407, 154, 111, 20);
		panelInfo.add(txtFldProvinsi);
		txtFldProvinsi.setColumns(30);
		txtFldProvinsi.setText("Sumatera Utara");

		JLabel lblNoTelepon = new JLabel("Telepon : ");
		lblNoTelepon.setFont(new Font("Arial", Font.PLAIN, 11));
		lblNoTelepon.setBounds(538, 157, 60, 14);
		panelInfo.add(lblNoTelepon);

		txtFldTelepon = new JTextField();
		txtFldTelepon.setFont(new Font("Arial", Font.PLAIN, 11));
		txtFldTelepon.setEditable(false);
		txtFldTelepon.setColumns(15);
		txtFldTelepon.setBounds(605, 154, 129, 20);
		panelInfo.add(txtFldTelepon);

		JLabel lblKeterangan = new JLabel("Keterangan");
		lblKeterangan.setFont(new Font("Arial", Font.PLAIN, 11));
		lblKeterangan.setBackground(new Color(102, 153, 204));
		lblKeterangan.setOpaque(true);
		lblKeterangan.setBounds(10, 192, 724, 14);
		panelInfo.add(lblKeterangan);

		txtAreaKeterangan = new JTextArea();
		txtAreaKeterangan.setFont(new Font("Arial", Font.PLAIN, 11));
		txtAreaKeterangan.setEditable(false);
		txtAreaKeterangan.setBounds(10, 217, 724, 88);
		panelInfo.add(txtAreaKeterangan);

		JPanel panelNB = new JPanel();
		FlowLayout fl_panelNB = (FlowLayout) panelNB.getLayout();
		fl_panelNB.setAlignment(FlowLayout.LEFT);
		panelNB.setBounds(20, 390, 744, 25);
		panelCenter.add(panelNB);

		JLabel lblNb = new JLabel("NB : * Harus diisi");
		panelNB.add(lblNb);

	}

	public void displayFrame(boolean state){
		setVisible(state);
	}
	
	public void addBtnNewListener(ActionListener l){
		btnNew.addActionListener(l);
	}
	
	public void addBtnEditListener(ActionListener l){
		btnEdit.addActionListener(l);
	}
	
	public void addBtnDeleteListener(ActionListener l){
		btnDelete.addActionListener(l);
	}
	
	public void addBtnSaveListener(ActionListener l){
		btnSave.addActionListener(l);
	}
	
	public void addBtnCancelListener(ActionListener l){
		btnCancel.addActionListener(l);
	}
	
	public void addBtnShowListListener(ActionListener l){
		btnShowList.addActionListener(l);
	}
	
	public void requestFocusTxtFldKode(){
		txtFldKode.requestFocusInWindow();
	}
	
	public void setEnabledBtnNew(boolean b){
		btnNew.setEnabled(b);
	}
	
	public void setEnabledBtnEdit(boolean b){
		btnEdit.setEnabled(b);
	}
	
	public void setEnabledBtnDelete(boolean b){
		btnDelete.setEnabled(b);
	}
	
	public void setEnabledBtnSave(boolean b){
		btnSave.setEnabled(b);
	}
	
	public void setEnabledBtnCancel(boolean b){
		btnCancel.setEnabled(b);
	}
	
	public void setEnabledBtnShowList(boolean b){
		btnShowList.setEnabled(b);
	}
	
	public String getKode() {
		return txtFldKode.getText();
	}
	
	public void setKode(String text){
		txtFldKode.setText(text);
	}

	public String getNama() {
		return txtFldNama.getText();
	}

	public void setNama(String text){
		txtFldNama.setText(text);
	}
	
	public String getHP() {
		return txtFldHP.getText();
	}
	
	public void setHP(String text){
		txtFldHP.setText(text);
	}

	public String getEmail() {
		return txtFldEmail.getText();
	}
	
	public void setEmail(String text){
		txtFldEmail.setText(text);
	}

	public String getKota() {
		return txtFldKota.getText();
	}
	
	public void setKota(String text){
		txtFldKota.setText(text);
	}

	public String getKodePos() {
		return txtFldKodePos.getText();
	}

	public void setKodePos(String text){
		txtFldKodePos.setText(text);
	}
	
	public String getProvinsi() {
		return txtFldProvinsi.getText();
	}
	
	public void setProvinsi(String text){
		txtFldProvinsi.setText(text);
	}

	public String getTelepon() {
		return txtFldTelepon.getText();
	}
	
	public void setTelepon(String text){
		txtFldTelepon.setText(text);
	}

	public String getKeterangan() {
		return txtAreaKeterangan.getText();
	}
	
	public void setKeterangan(String text){
		txtAreaKeterangan.setText(text);
	}

	public String getAlamat() {
		return txtAreaAlamat.getText();
	}
	
	public void setAlamat(String text){
		txtAreaAlamat.setText(text);
	}
	
	public void setTextFieldEditable(){
		txtFldKode.setEditable(true);
		txtFldNama.setEditable(true);
		txtFldHP.setEditable(true);
		txtFldEmail.setEditable(true);
		txtFldKodePos.setEditable(true);
		txtFldKota.setEditable(true);
		txtFldTelepon.setEditable(true);
		txtFldProvinsi.setEditable(true);
		txtAreaAlamat.setEditable(true);
		txtAreaKeterangan.setEditable(true);
	}
	
	public void setTextFieldNonEditable(){
		txtFldKode.setEditable(false);
		txtFldNama.setEditable(false);
		txtFldHP.setEditable(false);
		txtFldEmail.setEditable(false);
		txtFldKodePos.setEditable(false);
		txtFldKota.setEditable(false);
		txtFldTelepon.setEditable(false);
		txtFldProvinsi.setEditable(false);
		txtAreaAlamat.setEditable(false);
		txtAreaKeterangan.setEditable(false);
	}
	
	public void clearTextField(){
		txtFldKode.setText("");
		txtFldNama.setText("");
		txtFldHP.setText("");
		txtFldEmail.setText("");
		txtFldKodePos.setText("");
		txtFldKota.setText("");
		txtFldTelepon.setText("");
		txtFldProvinsi.setText("");
		txtAreaAlamat.setText("");
		txtAreaKeterangan.setText("");
	}
}
